<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .bg{
            background-color: aqua;
        }
    </style>
</head>
<body>
   用户名： <input type="text" id="user" value="">
   密 码：<input type="password" id="password" value="">
   <input type="button" id="btn" value="提交">
    
    <script>
        var user = document.getElementById("user");
        var password = document.getElementById("password");
        var btn = document.getElementById("btn");

        btn.onclick = function (){
            if (user.value.length < 3 || user.value.length > 6){
                user.className = "bg";
                return;
            }
            else{
                user.className = "";
            }
            if (password.value.length < 6 || password.value.length > 8){
                password.className = "bg";
                return;
            }
            else{ 
                user.className = "";
            }
            console.log("提交成功!")
        };
        

    </script>   
</body>
</html>